
Query_information proc far
; 函数：根据es:di              查询data段中的信息并显示
; 参数: ah = 1: 按名字查询  ah = 2: 按学号查询   al: 查询的字符串的长度 es:ip :查询的字符串的存放地址
; 返回：ax保存查询到的数据数量

    push bx
    push cx
    push dx

    push ax
    mov ax,ss:[bp+16h]

    mov cx,ax   ; cx表示当前有多少条信息
    pop ax
    cmp cx,00h   ; 无信息直接退出
    jz Query_information_finish  

    xor dh,dh
    mov dl,al   ; dx存放字符串长度

    cmp ah,01h
    jz Query_information_name
    cmp ah,02h
    jz Query_information_ID
    jmp Query_information_error

Query_information_name:
    mov bx,00h
    jmp Query_information_start  ;按名字查询 
Query_information_ID:
    mov bx,10h
    jmp Query_information_start  ;按学号查询


Query_information_start:
    mov ax,data
    mov ds,ax
    mov ax,0h
Query_information_cycle:
    push ax
    call far ptr Get_pointers   ;获取偏移地址
    cmp ax,0BADh
    jz Query_information_finish

    mov si,ax
    add si,bx
    mov ax,dx
    call far ptr Kmp ; check_equal   ; 

    cmp ax,1h  ;查询到相等字符串,直接打印
    jnz Query_information_continue
    sub si,bx
    call far ptr Display_one_information

    mov ax,ss:[bp]   ;总查询到的信息地址存储在ss:[bp]上
    add ax,1h
    mov ss:[bp],ax

Query_information_continue:

    pop ax
    inc ax
    cmp ax,cx
    jz Query_information_finish

    jmp Query_information_cycle





Query_information_finish:
    pop dx
    pop cx
    pop bx
    retf

Query_information_error:
    pop dx
    pop cx
    pop bx
    retf

Query_information endp


;================================================================


Query_information_Top proc far

Query_information_Top_start:
    dispmsg Query_information_introduce
    dispmsg next_row
    dispmsg input_t
    mov_dssi_to_cache_area2
    mov ax,0101h    ; 接收最大1字节的数字字符
    call far ptr Get_input
    xor ah,ah
    mov al,ds:[si]
    clear_area_ds _1
    cmp al,'1'
    jz Query_information_query_by_name
    cmp al,'2'
    jz Query_information_query_by_ID_Transfer

    jmp Query_information_Top_error

Query_information_Top_error_Transfer:
    jmp  Query_information_Top_error
Query_information_query_by_ID_Transfer:
    jmp  Query_information_query_by_ID


Query_information_query_by_name:
    dispmsg Query_by_name_ 
    dispmsg next_row_input_t
    mov_dssi_to_cache_area2
    mov ax,0E02h    ; 接收最大14字节的字母字符串
    call far ptr Get_input
    cmp ax,0BADh
    jz Query_information_Top_error_Transfer
    push ax
    dispmsg Talbe_titles
    dispmsg next_row 

    mov_esdi_to_cache_area2
    pop ax
    mov ah,01h
    mov al,10h
    call far ptr Query_information
    jmp Query_information_Top_finish





Query_information_query_by_ID:
    dispmsg Query_by_ID_
    dispmsg next_row_input_t
    mov_dssi_to_cache_area2
    mov ax,0C01h    ; 接收最大12字节的数字字符串
    call far ptr Get_input
    cmp ax,0BADh
    jz Query_information_Top_error
    push ax
    dispmsg Talbe_titles
    dispmsg next_row 

    mov_esdi_to_cache_area2
    pop ax
    mov ah,02h
    mov al,0Ch
    call far ptr Query_information
    jmp Query_information_Top_finish



Query_information_Top_error:
    dispmsg next_row
    jmp Query_information_Top_start

Query_information_Top_finish:
    dispmsg Query_Finish_
    dispmsg next_row
    mov_esdi_to_cache_area2
    clear_area_es _80

    mov ax,ss:[bp]
    mov bx,0h
    mov ss:[bp],bx
    dispmsg Query_information_Top_Found_ 
    call far ptr display_ax_dec
    dispmsg next_row


    retf
Query_information_Top endp

